#ifndef LOG_HANDER_H
#define LOG_HANDER_H

#include "EventHandler.h"
#include <ctime>
#include <iostream>
#include <string>

using std::cout;
using std::ostream;
using std::string;

// 打印日志
template <typename Event>
class LogHandler: public EventHandler<Event> {

  ostream& os_;

 LogHandler(ostream& os) : os_(os) {
  }

 public:
  static EventHandler<Event>* Create(ostream& os=cout) {
    return new LogHandler<Event>(os);
  }
  
  bool Handle(Event e) {

    time_t rawtime;
    time(&rawtime);

    string time_str = ctime(&rawtime);
    
    os_ << "[" << time_str.substr(0, time_str.size()-1) << "] "  <<  e << "\n";
    
    return true;
  }
  
  ~LogHandler() {

  }
};

#endif

